﻿using System;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using NavigationModule.Services;

namespace NavigationModule
{
    public class NavigationModule : IModule
    {
        private readonly IRegionManager _regionManager;
        public readonly IUnityContainer _container;

        public NavigationModule(IRegionManager regionManager, IUnityContainer container)
        {
            _regionManager = regionManager;
            _container = container;
        }

        public void Initialize()
        {
            // register views
            _container.RegisterType<Object, Views.TopNavigationView>(typeof(Views.TopNavigationView).Name);
            _container.RegisterType<Object, Views.LeftSideNavigationView>(typeof(Views.LeftSideNavigationView).Name);
            _container.RegisterType<Object, Views.GlobalCommandsView>(typeof(Views.GlobalCommandsView).Name);

            // register services
            var topNavService = new TopNavigationService(_container);
            var leftNavService = new LeftSideNavigationService();

            _container.RegisterInstance<ITopNavigationService>(topNavService, new ContainerControlledLifetimeManager());
            _container.RegisterInstance<ILeftSideNavigationService>(leftNavService, new ContainerControlledLifetimeManager());
        }
    }
}
